
/*******************************
********************************
Create subset of data for replication file 
Lahore metrobus 
********************************
*******************************/

***********************************	
* HH panel file 
***********************************	

	global 		covariates gender ageyears ageyearssq yearsed yearsedsq dist_cent dist_cent_sq census_* 

	global		data ""X:\Dropbox\Metrobus study\Followup 2015_encrypted\"" 
	global		replication ""X:\Dropbox\Metrobus study\Replication""
	
	cd 			$data

	use 		metrobus_panel, clear
	
	keep		if stay_years > 3 & new==1 & year > 2009 & t_q2==1

	keep 		zone_id zonegroup_ref personid_num year ///
					mindist* treat1 treat1_post treat2 treat2_post ///
					dist_anystop* publiccommute* commutemode* vehiclecommute ///
					$covariates weightperhh diststopgroup* post ///
					traveltime_ predict_traveltime_ travelfare_ ///
					workoutside* avgtime* ///
					uniquespn motorcycles educated blmotorcycle year2012

	
	cd			$replication

	quietly 	log using metrobus_panel_repfile_codebook.txt, text replace
	
	codebook
	
	quietly 	log close	
		
	save 		metrobus_panel_repfile, replace 

	
***********************************	
* Community file 	
***********************************	

	cd 			$data

	use 		community_panel, clear
	
	keep		traveltime_ travelfare_ year mindist1 

	cd			$replication

	quietly 	log using community_panel_repfile_codebook.txt, text replace
	
	codebook
	
	quietly 	log close	
	
	save		community_panel_repfile, replace 

	

***********************************	
* Rider survey 
***********************************	
	
	cd			$data
	
	use			ridersurvey , clear
	
	drop		if refusal==1
	
	keep		pre_cost_real post_cost weightresponders timecat Q5 ///
					none public private both foot rickshaw qingqi buswagon ///
					cycle motorbike car ed id wtp_yes_*
	
	
	cd			$replication

	quietly 	log using ridersurvey_repfile_codebook.txt, text replace
	
	codebook
	
	quietly 	log close	
	
	save		ridersurvey_repfile, replace 
	
	
***********************************	
* HIS survey 
***********************************	
	
	cd			$data

	use			his_treatment_trip , clear
	
	keep		if trip_purpose==2												// Only commutes to work used in the figures to be replicated 
	
	keep		public private walk mode_trip_simple_* educ_level_recode 
		
	cd			$replication

	quietly 	log using his_treatment_trip_repfile_codebook.txt, text replace
	
	codebook
	
	quietly 	log close	
	
	save		his_treatment_trip_repfile , replace 
	
	
***********************************	
* Appended surveys
***********************************	

	cd			$data
	
	use 		his_rider_appended , clear
	
	drop		if refusal==1
		
	keep 		if (mode_trip==9 & min_dist_treat1 < 5 & trip_purpose==2) ///
					| (source==2 & (Q4==1|Q8==1))  // Keep commute trips from either survey 

	replace 	weightresponders = 1 if source==1 										
	
	keep		edu_comparable_* source weightresponders 

	cd			$replication

	quietly 	log using his_rider_appended_codebook.txt, text replace
	
	codebook
	
	quietly 	log close	
	
	save		his_rider_appended_repfile , replace 
	

	
	
	
	
	
	
	
	
